package com.jeeplus.modules.guide.service;

import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.guide.mapper.AppointmentRecordMapper;
import com.jeeplus.modules.guide.model.domain.Appointment;
import com.jeeplus.modules.guide.model.domain.AppointmentRecord;
import com.jeeplus.modules.guide.model.domain.BusinessInfo;
import com.jeeplus.modules.guide.model.query.CancelAppointment;
import com.jeeplus.modules.guide.model.vo.AppointmentRecordOut;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * ClassName: appointmentRecordService
 * Function:  预约记录
 * Date:      2021/6/11 15:17
 *
 * @author hanKongbin
 * version    V1.0
 */
@DS("queuing")
@AllArgsConstructor
@Service
public class AppointmentRecordService {

    private final AppointmentRecordMapper appointmentRecordMapper;

    /**
     * 查询预约记录
     *
     * @param sysNo
     * @param businessId
     * @param workday
     * @param timePeriod
     * @return
     */
    public List<AppointmentRecord> queryAppointmentRecords(String sysNo, String businessId, List<String> workday, Integer timePeriod) {
        if (StringUtils.isEmpty(sysNo) || StringUtils.isEmpty(businessId) || CollectionUtils.isEmpty(workday)) {
            return new ArrayList<>();
        }
        return appointmentRecordMapper.queryAppointmentRecords(sysNo, businessId, workday, timePeriod);
    }

    /**
     * 查询已预约记录
     *
     * @param sysNo
     * @param businessId
     * @param timePeriod
     * @return
     */
    public List<AppointmentRecord> queryAppointmentRecordsCount(String sysNo, String businessId, String time, Integer timePeriod) {
        return appointmentRecordMapper.queryAppointmentRecordsCount(sysNo, businessId, time, timePeriod);
    }

    /**
     * 查询指定身份证,未取号预约记录
     *
     * @param cardId
     * @param time
     * @param businessId
     * @return
     */
    public List<AppointmentRecord> queryRecordsByCardId(String cardId, String time, String businessId, Integer timePeriod) {
        if (StringUtils.isEmpty(cardId)) {
            return new ArrayList<>();
        }
        return appointmentRecordMapper.queryRecordsByCardId(cardId, time, businessId, timePeriod);
    }

    /**
     * 查询指定身份证,未取号预约记录
     *
     * @return
     */
    public List<AppointmentRecordOut> queryRecordsByTell(String tell) {
        return appointmentRecordMapper.queryRecordsByTell(tell);
    }


    /**
     * 保存预约记录
     *
     * @param appointment
     * @return
     */
    public int save(Appointment appointment) {
        if (null == appointment) {
            return 0;
        }
        return appointmentRecordMapper.save(appointment);
    }

    /**
     * 查询业务详情
     *
     * @param businessId
     * @return
     */
    public List<BusinessInfo> queryBusiness(List<String> businessId) {
        if (CollectionUtils.isEmpty(businessId)) {
            return new ArrayList<>();
        }
        return appointmentRecordMapper.queryBusiness(businessId);
    }

    /**
     * 查询业务详情
     *
     * @param businessId
     * @return
     */
    public BusinessInfo queryBusinessById(String businessId) {
        if (StringUtils.isEmpty(businessId)) {
            return null;
        }
        return appointmentRecordMapper.queryBusinessById(businessId);
    }

    /**
     * 取消预约
     *
     * @param obj
     * @return
     */
    public int cancel(CancelAppointment obj) {
        if (null == obj || StringUtils.isEmpty(obj.getId())) {
            return 0;
        }
        return appointmentRecordMapper.delete(obj.getId());
    }

    public Integer queryRecordsByCardIdAndTime(String cardId, String time, Integer timeperiod){
        return appointmentRecordMapper.queryRecordsByCardIdAndTime(cardId,time,timeperiod);
    }
}
